<p>This rule raises an issue when code uses verbose patterns like <code>array[array.length - 1]</code>, <code>array.slice(-1)[0]</code>, or
<code>string.charAt(string.length - 1)</code> to access elements by index.</p>
<h2>Why is this an issue?</h2>
<p>JavaScript provides the <code>.at()</code> method as a modern, cleaner way to access array and string elements by index. This method is especially
useful for negative indexing, where you want to access elements from the end.</p>
<p>Older patterns like <code>array[array.length - 1]</code> or <code>array.slice(-1)[0]</code> are verbose and harder to read. They also have
performance implications - methods like <code>slice()</code> create new arrays, which uses extra memory and processing time.</p>
<p>The <code>.at()</code> method accepts both positive and negative indices. Negative indices count from the end, so <code>array.at(-1)</code> gets
the last element, <code>array.at(-2)</code> gets the second-to-last, and so on. This makes the code more expressive and easier to understand.</p>
<p>Using <code>.at()</code> also provides consistency across different JavaScript objects - it works the same way on arrays, strings, typed arrays,
NodeLists, and other array-like objects.</p>
<h3>What is the potential impact?</h3>
<p>Using outdated index access patterns makes code harder to read and maintain. Methods like <code>slice()</code> create unnecessary intermediate
arrays, which can impact performance in loops or frequently called functions. The verbose syntax also increases the chance of off-by-one errors when
calculating indices.</p>
<h3>How to fix?</h3>
<p>Replace <code>array[array.length - n]</code> with <code>array.at(-n)</code> for cleaner negative indexing.</p>
<h4>Non-compliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
const lastElement = array[array.length - 1]; // Noncompliant
const fifthFromEnd = array[array.length - 5]; // Noncompliant
</pre>
<h4>Compliant code example</h4>
<pre data-diff-id="1" data-diff-type="compliant">
const lastElement = array.at(-1);
const fifthFromEnd = array.at(-5);
</pre>
<h3>Documentation</h3>
<ul>
  <li> <a href="https://github.com/sindresorhus/eslint-plugin-unicorn#readme">eslint-plugin-unicorn</a> - Rule <a
  href="https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-at.md">prefer-at</a> </li>
  <li> Array.prototype.at() - MDN - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at">Official
  documentation for the Array.at() method</a> </li>
  <li> String.prototype.at() - MDN - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at">Official
  documentation for the String.at() method</a> </li>
</ul>
<h3>Related Rules</h3>
<ul>
  <li> unicorn/prefer-negative-index - <a
  href="https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-negative-index.md">ESLint rule that suggests using negative
  indexing with .at() method</a> </li>
</ul>
